"""
项目模型
支持项目管理系统的数据模型
"""

from datetime import datetime
from typing import Optional, Dict, Any, List
import uuid
from sqlalchemy import Column, String, DateTime, Text, JSON
from sqlalchemy.dialects.postgresql import UUID
from src.config.database import Base


class Project(Base):
    """项目数据模型"""
    __tablename__ = "projects"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    name = Column(String(200), nullable=False, index=True)
    description = Column(Text, nullable=True)
    state = Column(JSON, nullable=True)  # 存储项目状态信息
    created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)

    def to_dict(self) -> Dict[str, Any]:
        """将项目对象转换为字典"""
        return {
            "id": str(self.id),
            "name": self.name,
            "description": self.description,
            "state": self.state,
            "created_at": self.created_at.isoformat() if self.created_at is not None else None,
            "updated_at": self.updated_at.isoformat() if self.updated_at is not None else None
        }